package com.tang.user.service.impl;

import com.tang.common.entity.user.Admin;
import com.tang.common.entity.user.User;
import com.tang.user.authModel.SecurityUser;
import com.tang.user.service.AdminService;
import com.tang.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    @Autowired
    private UserService userService;

    @Autowired
    private AdminService adminService;

    @Autowired
    private PasswordEncoder passwordEncoder;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User user = userService.selectByUserName(username);
        Admin admin = adminService.selectByAdminName(username);
        String password = passwordEncoder.encode("admin");
        return new SecurityUser( "admin",password,AuthorityUtils.commaSeparatedStringToAuthorityList("admin"));
    }


}
